Skip to content

Conversation

@EdenWuyt
Copy link
Contributor

@EdenWuyt EdenWuyt commented Jan 6, 2026

Change Summary

/rooms/{id}/availability: Returns availabile slots for a single room grouped by date
/rooms/availability: Returns paginated results of availability for multiple rooms (in the sense that whether they can be booked within a time range) => which I think it is useful after starting to implement #24

Change Form

Fill this up (NA if not available). If a certain criteria is not met, can you please give a reason.

  • The pull request title has an issue number
  • The change works by "Smoke testing" or quick testing
  • The change has tests
  • The change has documentation

Other Information

Assumption:

Related issue

@EdenWuyt EdenWuyt marked this pull request as ready for review January 6, 2026 14:55
@EdenWuyt EdenWuyt marked this pull request as draft January 11, 2026 17:30
@EdenWuyt
Copy link
Contributor Author

I will add another endpoint /rooms/availability to quickly get all rooms' availibity with a date time filter.

@EdenWuyt EdenWuyt marked this pull request as ready for review January 12, 2026 17:57
…T. Update validation for parameters date format and date range. Date range must be <= 42 days (suppose 6 lines X 7 days in calendar).
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds two new availability API endpoints for meeting rooms: one that returns boolean availability for multiple rooms (whether they can be booked within a time range), and another that returns detailed available time slots for a single room grouped by date.

Changes:

  • Added /rooms/availability endpoint for paginated boolean availability across multiple rooms
  • Added /rooms/{id}/availability endpoint for detailed time slot availability for a single room
  • Implemented recurrence rule handling for both rooms and bookings to calculate available time slots

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 13 comments.

File Description
server/api/room/views.py Added helper functions and two new action methods for availability endpoints with logic to calculate free time slots by subtracting booked intervals from room schedules
server/api/room/tests.py Added comprehensive test suite covering various scenarios including recurrence rules, timezone handling, and edge cases
server/api/room/README.md Added API documentation for the two new availability endpoints with query parameters and examples

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 217 to 219
bookings = Booking.objects.filter(room=room).filter(
Q(recurrence_rule__isnull=False) |
Q(start_datetime__lt=end_datetime, end_datetime__gt=start_datetime)
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The booking query logic has a potential issue. The query uses an OR condition where it fetches bookings with recurrence rules OR bookings that overlap the datetime range. However, bookings with recurrence rules should also be checked for whether they overlap the datetime range based on their base start/end times. A recurring booking that has occurrences in the requested range but whose base datetime is outside the range will still be fetched and processed, which could include irrelevant occurrences. Consider restructuring the query or adding additional filtering logic to handle this case more efficiently.

Suggested change
bookings = Booking.objects.filter(room=room).filter(
Q(recurrence_rule__isnull=False) |
Q(start_datetime__lt=end_datetime, end_datetime__gt=start_datetime)
bookings = Booking.objects.filter(
room=room,
start_datetime__lt=end_datetime,
end_datetime__gt=start_datetime,

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, bookings with recurrence rules should also be checked for whether they overlap the datetime range based on their base start/end times. => Not true. For example, the start_datetime and end_datetime can all be in 20260101 but the booking lasts a year.
However, it reminds me that only confirmed booking should be in it, i.e., .filter(room=room, status="CONFIRMED")

Comment on lines 125 to 132
results.append({"room_id": room.id, "availability": True})
# If end_datetime is earlier than now, the room cannot be booked
elif end_datetime < current_time:
for room in page:
results.append({"room_id": room.id, "availability": False})
else:
for room in page:
availability = self._calculate_boolean_availability(room, start_datetime, end_datetime)
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inactive rooms are not filtered out before calculating availability in the get_rooms_availability endpoint. While unauthenticated users will only see active rooms (via get_queryset), authenticated users could see inactive rooms marked as available, which is inconsistent with the behavior in get_room_availability (line 146-147) that returns empty availability for inactive rooms. Consider adding a check for room.is_active before calculating availability, or filtering inactive rooms as unavailable for consistency.

Suggested change
results.append({"room_id": room.id, "availability": True})
# If end_datetime is earlier than now, the room cannot be booked
elif end_datetime < current_time:
for room in page:
results.append({"room_id": room.id, "availability": False})
else:
for room in page:
availability = self._calculate_boolean_availability(room, start_datetime, end_datetime)
# Inactive rooms should not be considered available
availability = bool(room.is_active)
results.append({"room_id": room.id, "availability": availability})
# If end_datetime is earlier than now, the room cannot be booked
elif end_datetime < current_time:
for room in page:
results.append({"room_id": room.id, "availability": False})
else:
for room in page:
# Inactive rooms have no availability
if not room.is_active:
availability = False
else:
availability = self._calculate_boolean_availability(
room,
start_datetime,
end_datetime,
)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add availability API endpoints

2 participants